var flowChar;
var userChar;
var sbSucessChar;
var sbsyChar;
var attachChar;
var IndexMapdata;
var isFirst=0;//判断是否初次加载还是点击按钮查询
$(function() {
	//初始化图表
	initFlowChar();
	initUserChar();
    userNum(0);
	initSbSucessChar();
	initSbsyChar();
	initAttachChar();
    $("input[name='showType']").click(function(){
        changeShowData();


    });
    
    attachChar.on('click', function(param) {
		attaLinkTo(param.seriesName,param.name);
	});
	flowChar.on('click',function(param){
		flowLinkTo(param.seriesName);
	});
	userChar.on('click',function(param){
		userLinkTo(param.seriesName);
	});
	sbsyChar.on('click',function(param){
		sbsyLinkTo(param.seriesName,param.name);
	});
})

function flowLinkTo(name) {
	var p ="";
	if (name == '今天') {
		p = "&dayType=today"
	}else{
		p = "&dayType=yesterday"
	}
	url = "/excavantionAnalysis/applicationAnalysis/index?" + p;
	title = "应用挖掘"
	linkTab(title, url)
}

function sbsyLinkTo(name,eCharsTime) {
	var p ="jspType=main&eCharsTime="+eCharsTime;
	if (name == '今天') {
		p += "&dayType=today"
	}else{
		p += "&dayType=yesterday"
	}
	url = "/businessAnalysis/hcq/index?" + p;
	title = "HTTP过程指标"
	linkTab(title, url)
}

function userLinkTo(name) {
	var p ="";
	if (name == '今天') {
		p = "&dayType=today"
	}else{
		p = "&dayType=yesterday"
	}
	url = "/excavantionAnalysis/areaanalysis/index?" + p;
	title = "区域分析"
	linkTab(title, url)
}

function attaLinkTo(name,eCharsTime) {
	var p ="";
	if (name == '今天') {
		p = "&dayType=today"
	}
	if (name == '昨天') {
		p = "&dayType=yesterday"
	}
	p += "&eCharsTime="+eCharsTime
	url = "/businessAnalysis/attachment/index?" + p;
	title = "附着质量分析"
	linkTab(title, url)
}

function initFlowChar() {
	// 查询
	flowChar = echarts.init(document.getElementById('flowChar'));
	flowChar.clear();
	flowChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../main/getFlowChar?rand="+Math.random(),
		dataType : "json",
//		"data" : {
//			"allData" : JSON.stringify(d)
//		},
		success : function(data) {
			flowChar.setOption(data, true);
			flowChar.hideLoading();
		}
	});
}

function initUserChar() {
	// 查询
	userChar = echarts.init(document.getElementById('userChar'));
	userChar.clear();
	userChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../main/getUserChar?rand="
				+ Math.random(),
		dataType : "json",
//		"data" : {
//			"allData" : JSON.stringify(d)
//		},
		success : function(data) {
			userChar.setOption(data, true);
			userChar.hideLoading();
		}
	});
}

function initSbSucessChar() {
	// 查询
	sbSucessChar = echarts.init(document.getElementById('sbSucessChar'));
	sbSucessChar.clear();
	sbSucessChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../main/getSbSucessChar?rand="
				+ Math.random(),
		dataType : "json",
//		"data" : {
//			"timeSize" : timeSize,
//			"beginDate" : beginDate,
//			"endDate" : endDate,
//			"netYuan" : netYuan,
//			"area" : area,
//			"userId" : userId,
//			"terminalType" : terminalType,
//			"failureReason" : failureReason,
//			"quota" : quota
//		},
		success : function(data) {
			sbSucessChar.setOption(data, true);
			sbSucessChar.hideLoading();
		}
	});
}

function initSbsyChar() {
	// 查询
	sbsyChar = echarts.init(document.getElementById('sbsyChar'));
	sbsyChar.clear();
	sbsyChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../main/getSbsyChar?rand="
				+ Math.random(),
		dataType : "json",
//		"data" : {
//			"timeSize" : timeSize,
//			"beginDate" : beginDate,
//			"endDate" : endDate,
//			"netYuan" : netYuan,
//			"area" : area,
//			"userId" : userId,
//			"terminalType" : terminalType,
//			"failureReason" : failureReason,
//			"quota" : quota
//		},
		success : function(data) {
			sbsyChar.setOption(data, true);
			sbsyChar.hideLoading();
		}
	});
}

function initAttachChar() {
	// 查询
	attachChar = echarts.init(document.getElementById('attachChar'));
	attachChar.clear();
	attachChar.showLoading({
		text : '正在努力的读取数据中...'
	});
	$.ajax({
		type : "POST",
		url : "../main/getAttachChar?rand="
				+ Math.random(),
		dataType : "json",
//		"data" : {
//			"timeSize" : timeSize,
//			"beginDate" : beginDate,
//			"endDate" : endDate,
//			"netYuan" : netYuan,
//			"area" : area,
//			"userId" : userId,
//			"terminalType" : terminalType,
//			"failureReason" : failureReason,
//			"quota" : quota
//		},
		success : function(data) {
			attachChar.setOption(data, true);
			attachChar.hideLoading();
		}
	});
}

function userNum(isFirst){
    if(isFirst==0){
        layer.load(2);
    }else{
        window.frames['map'].layerLoad();
    }

    $.ajax({
        type : "POST",
        url : "../mapAnalysis/UserAndFlowHeatMap",

        dataType : "json",
        success : function(data) {

            var count;
            if(data){
                IndexMapdata=data;
                window.frames['map'].initMapData();
            //    window.frames['map'].layerLoad();
                changeShowData();
               /* window.frames['map'].initData(data,{
                    type:"groupMap",
                    data:"flow",
                    cityCode:"cityName",
                    max:100,//值
                    count:"count"
                });
                window.frames['map'].initData(data,{
                    type:"groupMap",
                    data:"flow",
                    cityCode:"cityName",
                    max:100,//值
                    count:"count"
                });*/
            }
        }
    });
}

function changeShowData(){
  var showType= $('input:radio[name="showType"]:checked').val();
  alert(showType);  
  if(!IndexMapdata[showType]){
        if(isFirst==0){
            layer.closeAll('loading');
        }

        window.frames['map'].noMapdata();
    }else{
        var isReposition=false;
        if(isFirst==0){
            isReposition=true;
        }else{
            isReposition=false;
        }
        window.frames['map'].initData(IndexMapdata,{
            type:"groupMap",
            data:showType,
            cityCode:"cityName",
            max:100,//值
            count:"count",
            isRePlace:isReposition
        });
        if(isFirst==0){
            layer.closeAll('loading');
        }
        window.frames['map'].closeLayer();


    }
    if(isFirst==0){
        isFirst=1;
    }

}